using NHibernate.Criterion;

namespace WineCellar.Core.NHibernate
{
    public class NHibernateHelper
    {
        public static AbstractCriterion TranslateSearchParametersToNHibernateCriterion(string column, object value,
                                                                                       string method)
        {
            switch (method)
            {
                case "Like":               
                    {
                        return new LikeExpression(column, value.ToString(), MatchMode.Start);
                    }
                case "IsSmallerThan":                
                    {
                        return new SimpleExpression(column, value, " <= ");
                    }
                case "IsLargerThan":                
                    {
                        return new SimpleExpression(column, value, " >= ");
                    }
                case "Is":                
                    {
                        return new SimpleExpression(column, value, " = ");
                    }
                case "IsLargerThanOrNull":
                    {
                        return Restrictions.Or(Restrictions.Gt(column, value), Restrictions.IsNull(column));
                    }
                case "IsNull":
                    {
                        return Restrictions.IsNull(column);
                    }                
                default:
                    {
                        return new SimpleExpression(column, value, " = ");
                    }
            }
        }
    }
}